import { defineStore } from 'pinia'

export const useLoginStore = defineStore('login', {
	state: () => {
		return {
			userInfo: localStorage["userInfo"]?
				JSON.parse(localStorage["userInfo"]):null,
			token:localStorage["token"]
		}
	},
	actions: {
		async userLogin(userInfo,token) {
			this.userInfo=userInfo;
			this.token=token;
			localStorage.setItem("userInfo",JSON.stringify(userInfo) );
			localStorage.setItem("token",token);
		},
		async logout(){
			this.userInfo=null;
			this.token=null;
			localStorage.setItem("userInfo",null);
			localStorage.setItem("token",null);
		}
	}
})